package de.koller.reason.gui.component;

import de.koller.reason.gui.GUIRoot;
import de.koller.reason.gui.renderObj.IRenderObject;
import de.koller.reason.gui.renderObj.IRenderPosition;
import de.koller.reason.gui.textureObj.IPart;
import java.util.Set;

public class RPanel extends RComponent implements IRenderObject {

	private IPart visual;
	private Set<IRenderObject> containedSet;
	protected GUIRoot gui = null;
	
	public RPanel( IPart visual ) {
		super();
		this.setWidth( visual.getSubWidth() );
		this.setHeight( visual.getSubHeight() );
		
		this.visual = visual;
	}
	
	public void addTo( GUIRoot gui, Set<IRenderObject> renderSet ) {
		if( !renderSet.add( this ) )
			throw new IllegalArgumentException( "panel already added!" );
		this.containedSet = renderSet;
		this.gui = gui;
	}
	
	public void removeFrom( GUIRoot gui ) {
		if( !containedSet.remove( this ) )
			throw new IllegalArgumentException( "panel not yet added!" );
		this.containedSet = null;
		this.gui = null;
	}
	
	@Override
	public IRenderPosition getRenderPos() {
		return this;
	}

	@Override
	public IPart getSubPart() {
		return visual;
	}

	public void setVisual( IPart visual ) {
		this.visual = visual;
	}
	
}
